package common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Iterator;
import java.sql.Connection;
import db.CommonConnect;
import db.DAO;



public class Agent_db_run {
	public Agent_db_run() {
	}
	 public static void main(String args[])throws Exception
	 {
		String queryStr = "";
	    String temp = "";
		Connection 	con 	= null;
		String[] 	param 	= null;
		ArrayList 	list 	= null;
		HashMap 	map 	= null;
		try {
			con = (new CommonConnect()).getConnection_ds1();
			con.setAutoCommit(true);
			queryStr = "call "+args[0];
		  	if (args.length == 1){
		  		list = DAO.select(con,queryStr);
		  	}else{
		  		param = new String[args.length -1];
		  		for (int i =0; i < param.length;i++){
		  			param[i] = args[i+1];
		  		}
		  		list = DAO.select(con,queryStr,param);
		  	}
		  	
		    if (list!=null && list.size()> 0){
		    	map=(HashMap)list.get(0);
		    	Set set = map.entrySet();
		    	Iterator iterator = set.iterator();
		    	while (iterator.hasNext()){
		    		Entry entry = (Entry)iterator.next();
		    		temp += entry.getKey() +":"+ entry.getValue() +"|"; 		
		    	}
		    }
	
			String inDate   = new java.text.SimpleDateFormat("yyyyMMdd").format(new java.util.Date());
			String inTime   = new java.text.SimpleDateFormat("HHmmss").format(new java.util.Date());
		    System.out.println(inDate + inTime +":"+ queryStr+" excuted at \n	"+ temp );
		  }catch(Exception e)
		  {
				String inDate   = new java.text.SimpleDateFormat("yyyyMMdd").format(new java.util.Date());
				String inTime   = new java.text.SimpleDateFormat("HHmmss").format(new java.util.Date());
		
			  // 오류정보를 시스템 컨솔에 출력
			   System.out.println(inDate + inTime +":Exception= "+e.getMessage());
		  }
	  }
}
